package com.cqc.adapterjava;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView tv;
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LogUtil.d(TAG,"onCreate");

        tv = (TextView) findViewById(R.id.tv);
        //拿到屏幕的宽高
        getWindowParams();
    }

    private void getWindowParams() {
        //创建对象
        DisplayMetrics metrics = new DisplayMetrics();
        //将宽高信息存放在对象中
        MainActivity.this.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        //取值
        int width = (int) (metrics.widthPixels/2 + 0.5);
        int height = (int) (metrics.heightPixels/5+0.5);

        //设置宽高,至于导入哪个layout，要看tv的父布局是哪个layout
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width,height);
        tv.setLayoutParams(params);
    }
}
